package com.irdstudio.esaas.amcenter.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.esaas.amcenter.service.api.AppBaseInfoService;
import com.irdstudio.esaas.amcenter.dao.AppBaseInfoDao;
import com.irdstudio.esaas.amcenter.dao.domain.AppBaseInfo;
import com.irdstudio.esaas.amcenter.service.vo.AppBaseInfoVO;
import com.irdstudio.ssm.framework.service.FrameworkService;
/**
 * <p>ServiceImpl: 01.APP基本信息表				<p>
 * @author ligm
 * @date 2018-08-25
 */
@Service("appBaseInfoServiceImpl")
public class AppBaseInfoServiceImpl implements AppBaseInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(AppBaseInfoServiceImpl.class);

	@Autowired
	private AppBaseInfoDao appBaseInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertAppBaseInfo(AppBaseInfoVO inAppBaseInfoVo) {
		logger.debug("当前新增数据为:"+ inAppBaseInfoVo.toString());
		int num = 0;
		try {
			AppBaseInfo appBaseInfo = new AppBaseInfo();
			beanCopy(inAppBaseInfoVo, appBaseInfo);
			num = appBaseInfoDao.insertAppBaseInfo(appBaseInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(AppBaseInfoVO inAppBaseInfoVo) {
		logger.debug("当前删除数据条件为:"+ inAppBaseInfoVo);
		int num = 0;
		try {
			AppBaseInfo appBaseInfo = new AppBaseInfo();
			beanCopy(inAppBaseInfoVo, appBaseInfo);
			num = appBaseInfoDao.deleteByPk(appBaseInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inAppBaseInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(AppBaseInfoVO inAppBaseInfoVo) {
		logger.debug("当前修改数据为:"+ inAppBaseInfoVo.toString());
		int num = 0;
		try {
			AppBaseInfo appBaseInfo = new AppBaseInfo();
			beanCopy(inAppBaseInfoVo, appBaseInfo);
			num = appBaseInfoDao.updateByPk(appBaseInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inAppBaseInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public AppBaseInfoVO queryByPk(AppBaseInfoVO inAppBaseInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inAppBaseInfoVo);
		try {
			AppBaseInfo queryAppBaseInfo = new AppBaseInfo();
			beanCopy(inAppBaseInfoVo, queryAppBaseInfo);
			AppBaseInfo queryRslAppBaseInfo = appBaseInfoDao.queryByPk(queryAppBaseInfo);
			if (Objects.nonNull(queryRslAppBaseInfo)) {
				AppBaseInfoVO outAppBaseInfoVo = beanCopy(queryRslAppBaseInfo, new AppBaseInfoVO());
				logger.debug("当前查询结果为:"+ outAppBaseInfoVo.toString());
				return outAppBaseInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AppBaseInfoVO> queryAllOwner(AppBaseInfoVO appBaseInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<AppBaseInfoVO> list = null;
		try {
			List<AppBaseInfo> appBaseInfos = appBaseInfoDao.queryAllOwnerByPage(appBaseInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ appBaseInfos.size());
			pageSet(appBaseInfos, appBaseInfoVo);
			list = (List<AppBaseInfoVO>) beansCopy(appBaseInfos, AppBaseInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AppBaseInfoVO> queryAllCurrOrg(AppBaseInfoVO appBaseInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<AppBaseInfo> appBaseInfos = appBaseInfoDao.queryAllCurrOrgByPage(appBaseInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+appBaseInfos.size());
		List<AppBaseInfoVO> list = null;
		try {
			pageSet(appBaseInfos, appBaseInfoVo);
			list = (List<AppBaseInfoVO>) beansCopy(appBaseInfos, AppBaseInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<AppBaseInfoVO> queryAllCurrDownOrg(AppBaseInfoVO appBaseInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<AppBaseInfo> appBaseInfos = appBaseInfoDao.queryAllCurrDownOrgByPage(appBaseInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ appBaseInfos.size());
		List<AppBaseInfoVO> list = null;
		try {
			pageSet(appBaseInfos, appBaseInfoVo);
			list = (List<AppBaseInfoVO>) beansCopy(appBaseInfos, AppBaseInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
